package net.xdclass.controller;



import net.xdclass.model.vo.ProductVO;
import net.xdclass.service.ProductService;
import net.xdclass.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小冯
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 查看所有商品
     * @return
     */
    @GetMapping("list")
    public JsonData list(){
        List<ProductVO> productVOList = productService.list();
        return JsonData.buildSuccess(productVOList);
    }

    /**
     * 查看详情
     * @return
     */
    @GetMapping("detail/{product_id}")
    public JsonData detail(@PathVariable("product_id")long productId){
        ProductVO productVO = productService.detail(productId);
        return JsonData.buildSuccess(productVO);
    }


}

